/**
 * // Definition for a Node.
 * function Node(val, children) {
 *    this.val = val;
 *    this.children = children;
 * };
 */

/**
 * @param {Node|null} root
 * @return {number[]}
 */
// 用递归
var preorder = function(root) {
    if(root == null) return []
    let ans = []
    const iter = (p) => {
        ans.push(p.val)
        for(let i = 0; i < p.children.length; i++) {
            iter(p.children[i])
        }
    }
    iter(root)
    return ans
};
// 用迭代
